<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>北京市人民政府外事办公室领事保护教育服务平台</title>
	<!-- 新 Bootstrap 核心 CSS 文件 -->
	<link rel="stylesheet" href='<c:url value="/share/bootstrap.min.css"></c:url>'> 
	<link rel="stylesheet" href='<c:url value="/share/AllStyle.css"></c:url>'> 
	<script src='<c:url value="/js/jquery.min.js"></c:url>'></script>
	<script src='<c:url value="/js/bootstrap.min.js"></c:url>'></script>
	<script src='<c:url value="/js/all.js"></c:url>'></script> 
	<style>
		.table>thead:first-child>tr:first-child>th {
		    font-weight: 300;
		}
	</style>
</head>
<body>
	<div class="home_header_2">
		<div class="Interface_center Interface_relative">
			<ul>
				<li>
					<div>试题类型：</div>
					<ul class="Interface_relative">
						<li><a href="javascript:onselect(0);" class="home_header_2_Click">全部</a></li>
						<li><a href="javascript:onselect(1);">留学</a></li>
						<li><a href="javascript:onselect(2);">务工</a></li>
						<li><a href="javascript:onselect(3);">旅行</a></li>
						<li><a href="javascript:onselect(4);">商贸</a></li>
						<li><a href="javascript:onselect(5);">反恐</a></li>
						<li><a href="javascript:onselect(6);">疫情</a></li>
						<li><a href="javascript:onselect(7);">法律纠纷</a></li>
						<li><a href="javascript:onselect(8);">刑事案件</a></li>
					</ul>
				</li>
				<!-- <li>
					<div>排序：</div>
					<ul class="Interface_relative">
						<li><a href="javascript:;" class="home_header_2_Click">最新</a></li>
						<li><a href="javascript:;">最热</a></li>
					</ul>
				</li> -->
			</ul>
			<div class="home_header_2_Arrow home_header_2_Arrow_true" style="padding: 0;height: 16px;">
				<img src='<c:url value="/share/images/Arrow.png"></c:url>' style="margin-bottom: 6px;" class="transform_rotate"/>
			</div>
		</div>
	</div>
	<div class="home_content Interface_center">
		<div class="input-group input-group" style="float: right;width: 290px;margin-top: 15px;margin-bottom: 24px;">
			<input type="text" name="q" id="name" value="" placeholder="输入试题名称" class="form-control" size="40" style="border: 1px solid #82bcff;">
			<span class="input-group-btn">
				<a class="btn btn-primary" id = "search" style="background:#82bcff;border-color: #82bcff;font-weight: 300;">搜索</a>
			</span>
		</div>
		<table class="table case_table">
	    	<thead style="background: #2459aa; color: #fff;border: 1px solid #337ab7;">
		        <tr>
		          <th>序列号</th>
		          <th style="padding-left: 20px;padding-right: 20px;">试卷名称</th>
		          <th>试卷类型</th>
		          <th>发布时间</th>
		          <th>试卷状态</th>
		          <th>试卷总分</th>
		          <th>得分</th>
		          <!-- <th>阅卷人</th> -->
		          <!-- <th>操作</th> -->
		        </tr>
		    </thead>
	      <tbody id="Examination_details">
	      </tbody>
	    </table>
		<br>
		<br>
		<div id="WH-pagebar" class="WH-pagebar"></div>
		<br>
		<br>
	</div>

	<script type="text/javascript">
		$(function(){
			$(".home_header-nav li").click(function(){
				$(".home_header-nav li a").removeClass("home_header_1_ClickA");
				$(this).children().addClass("home_header_1_ClickA");
			});
			$(".home_header_2 .Interface_center>ul>li:eq(0) ul li").click(function(){
				$(".home_header_2 .Interface_center>ul>li:eq(0) ul li a").removeClass("home_header_2_Click");
				$(this).children().addClass("home_header_2_Click");
			});
			$(".home_header_2 .Interface_center>ul>li:eq(1) ul li").click(function(){
				$(".home_header_2 .Interface_center>ul>li:eq(1) ul li a").removeClass("home_header_2_Click");
				$(this).children().addClass("home_header_2_Click");
			});
			$(".home_header_2_Arrow").click(function(){
				if(!$(this).is(".home_header_2_Arrow_true")){
					$(this).prevAll().hide();
					$(this).children().addClass("transform_rotate");
					$(this).addClass("home_header_2_Arrow_true");
				}else{
					$(this).prevAll().show();
					$(this).children().removeClass("transform_rotate");
					$(this).removeClass("home_header_2_Arrow_true");
				}
			});
		});
		var rootPath = '${rootPath}/';
		var user = '${user}';
		var currentPage = 1;
		var allPage = 1;
		var type = 0;
		var searchValue;
		var pageSize = 20;
		var isFirst = true;
		$(function(){
			if(!user){
				alert("请先登录");
			}else{
				onselect(0);
			}
		})
		$("#search").click(function(){
			onsearch();
		})
		var count_1;
		function getlist(count_1){
			var url = rootPath+"exam/list";
			var object = new Object;
			object.pageSize = pageSize.toString();
			var start;
			if(currentPage > 1){
				start = (currentPage-1)*pageSize;
			}else{
				start = 0;
			}
			object.postion = start;
			object.type = type.toString();
			object.value = searchValue;
			var json = JSON.stringify(object);
			$.ajax({
				url:url,
				method:"post",
				dataType:"json",
				data:{
					'data':json
				},
				success:function(data){
					if(data){
						show(data.list,object.pageSize);
						count_1 = data.sum;
					}else{
						alert("获取数据失败！");
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
					if(isFirst){
						creatPageBar(count_1,pageSize);
			            isFirst = false;
			        }
				},
				error:function(){
					alert("未知错误！");
				}
				
			});
		}
		function show(data,pageSize){
			var htmStr = "";
			if(!data){
				$("#Examination_details").html("<p style=\"margin-left:700px\" >没有数据！</p>");
				return;
			}
			var Index = pageSize * (currentPage-1);
			for(var i = 0;i < data.length;i++){
				htmStr += "<tr onclick = \"operate("+data[i].id+","+data[i].mId+","+data[i].isAuto+","+data[i].mstate+")\"><td>"+ (Index+i+1) +"</td><td scope=\"row\" style='padding-left: 20px;padding-right: 20px;'>"+data[i].name+"</th>"
				+"<td title='"+data[i].type_name+"'>"+data[i].type_name+"</td>"
				+"<td title='"+data[i].createTime.replace("T"," ")+"'>"+data[i].createTime.replace("T"," ")+"</td>"
				+"<td title='"+stateStr(data[i].mstate)+"'>"+stateStr(data[i].mstate)+"</td>"
			    +"<td title='"+trans(data[i].sumScore)+"'>"+trans(data[i].sumScore)+"</td>"
			    +"<td title='"+trans(data[i].mscore)+"'>"+trans(data[i].mscore)+"</td>";
			   /*  +"<td>"+stateStr(data[i].marker)+"</td>"; */
			}
			$("#Examination_details").html(htmStr);
		}
		function stateStr(str){
			if(str == "0"){
				str = "未答题";
			}else if(str == "1"){
				str = "已答";
			}else if(!str){
				str = "未答题";
			}
			return str;
		} 
		function trans(str){
			if(!str){
				str = "";
			}
			return str;
		}
		function operate(examId,mid,isAuto,state){
			
			var url=null;
			if(!mid){
				mid = "0";
			}
			if(state==1){
				url = rootPath + 'exam/paperInfo/' + mid +'/'+examId;
			}else if(isAuto == 1){
				isAuto = "auto";
				url = rootPath + 'exam/examMv/' + mid +'/'+examId +"/"+ isAuto;
			}else if(isAuto == 0){
				isAuto = "hand";
				url = rootPath + 'exam/examMv/' + mid +'/'+examId +"/"+ isAuto;
			}
			window.open(url); 
		}
		//筛选
		function onselect(str){
			currentPage = 1;
			type = str;
			isFirst=true;
			getlist(count_1);
		}
		
		function onsearch(){
			currentPage = 1;
			searchValue = $("#name").val();
			$("#name").val("");
			isFirst=true;
			getlist(count_1);
		}
		
		function navclick(postion){
			//alert(postion);
			if(postion == "last"){
				if(currentPage > 1){
					currentPage -= 1;
				}
			}else if(postion == "next"){
				if(currentPage < allPage){
					currentPage += 1;
				}
			}else{
				currentPage = postion;
			}
			getlist();
		}
		
		function creatPageBar(count,PageSize){
			var WHPageBar = document.getElementById('WH-pagebar');
			var SingleCount = Math.ceil(count/PageSize);//翻页显示个数
			var PageCount = Math.ceil(count/PageSize);//总页数
			WHPageBar.innerHTML="";
			WH_Pagebar({
				id:'WH-pagebar', //容器ID : 必选参数
				CurrentPage:currentPage,   //当前页 ： 可选参数，默认值为1
				SingleCount:SingleCount,   //显示数目： 可选参数，只能为奇数，默认值为7，
				PageCount:PageCount,   //必选参数
				callback : function(pagenow,pagecount){	
					currentPage = pagenow;
					_getlist(count_1);
				}
			})
		}
		
		function _getlist(count_1){
			var url = rootPath+"exam/list";
			var object = new Object;
			object.pageSize = pageSize.toString();
			var start;
			if(currentPage > 1){
				start = (currentPage-1)*pageSize;
			}else{
				start = 0;
			}
			object.postion = start;
			object.type = type.toString();
			object.value = searchValue;
			var json = JSON.stringify(object);
			$.ajax({
				url:url,
				method:"post",
				dataType:"json",
				data:{
					'data':json
				},
				success:function(data){
					if(data){
						show(data.list,object.pageSize);
						count_1 = data.sum;
					}else{
						alert("获取数据失败！");
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
				},
				error:function(){
					alert("未知错误！");
				}
				
			});
		}
	</script>
</body>
</html>
